package com.hdey.service.max.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdey.mapper.max.TbUscDictionaryMapper;
import com.hdey.pojo.max.TbUscDictionary;
import com.hdey.service.max.TbUscDictionarySvs;
import com.hdey.vo.DictionaryForSearch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Service("tbUscDictionarySvs")
@Transactional
@Slf4j
public class TbUscDictionarySvsImpl extends ServiceImpl<TbUscDictionaryMapper, TbUscDictionary> implements TbUscDictionarySvs {

   @Resource
   private TbUscDictionaryMapper dictionaryMapper;


    @Override
    public List<TbUscDictionary> getTbUscDictionary(DictionaryForSearch dictionary) {
        LambdaQueryWrapper<TbUscDictionary> wrapper = new LambdaQueryWrapper<>();

        if(dictionary.getCgCode() != null && !"".equals(dictionary.getCgCode() )){
            wrapper.eq(TbUscDictionary::getCgCode,dictionary.getCgCode());
        }

        if(dictionary.getCgName() != null && !"".equals(dictionary.getCgName() )){
            wrapper.like(TbUscDictionary::getCgName,dictionary.getCgName());
        }
        if(dictionary.getInputCode() != null && !"".equals(dictionary.getInputCode() )){
            wrapper.like(TbUscDictionary::getInputCode,dictionary.getInputCode());
        }

        List<TbUscDictionary> list = dictionaryMapper.selectList(wrapper);

        return list;
    }


    @Override
    public Integer createTbUscDictionary(TbUscDictionary dictionary) {
        dictionary.setCreateBy("admin");
        dictionary.setCreateDate(LocalDate.now());
        int result = dictionaryMapper.insert(dictionary);
        return result;
    }

    @Override
    public Integer updateTbUscDictionary(TbUscDictionary dictionary) {
        dictionary.setUpdateBy("admin");
        dictionary.setUpdateDate(LocalDate.now());
        int result = dictionaryMapper.updateById(dictionary);
        return result;
    }

    @Override
    public Integer deleteTbUscDictionary(Integer dictionaryId) {
        int result = dictionaryMapper.deleteById(dictionaryId);
        return result;
    }


}
